//
//  YYEDiscoverSearchView.swift
//  weibo14
//
//  Created by mac on 16/3/2.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit

class YYEDiscoverSearchView: UIView {


    // 点击了
    
    @IBAction func btnClick(sender: UIButton) {
    
        layoutnum.constant = -sender.frame.width
    
        UIView.animateWithDuration(0.4) { [weak self] in

            self!.searchField.layoutIfNeeded()
        }
        
        searchField.resignFirstResponder()
    }
    
    
    @IBOutlet weak var cancelBtn: UIButton!
    
    // 搜索栏
    @IBOutlet weak var searchField: UITextField!
    
    

    // 结束按钮
    @IBAction func editingDidBegin(sender: UITextField) {
        
        layoutnum.constant = 0;
        
        UIView.animateWithDuration(0.4) { [weak self] in
            
            self!.searchField.layoutIfNeeded()
        }
    }
    
    
    @IBOutlet weak var layoutnum: NSLayoutConstraint!
    
    
    
    
    
    override func awakeFromNib() {
        
        imageSearch.frame.size = CGSize(width: self.frame.height, height: self.frame.height)
        searchField.leftView = imageSearch
        searchField.leftViewMode = .Always
        
    }
    
    // !!! 便利构造函数 class 一定不能忘记
    // 这不是便利构造函数 是一个类方法  提供给外界的 类  方法
    class func searchView() -> YYEDiscoverSearchView {
    
         return NSBundle.mainBundle().loadNibNamed("YYEDiscoverSearchView", owner: nil, options: nil).last as! YYEDiscoverSearchView
    }
    

   // 懒加载最左的图片
    
    
    private lazy var  imageSearch: UIImageView = {
    
        let view = UIImageView(image: UIImage(named: "searchbar_textfield_search_icon"))
      
       // 这很重要没有会让图片自动的方大
        view.contentMode = .Center
        
        return view
    }()
    
    
}
